﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;

namespace Acms.AcmsControls.ContentControls.FrontEnd
{
    /// <summary>
    /// Renders the Current post or containing posts Summary in "p" tags
    /// </summary>
    public class PostSummary : BasePostPropertyControl
    {
        public override void DataBind()
        {
            var post = FindCurrentPost();
            if (post != null)
            {
                Text = post.Summary;
            }
            else
            {
                Text = "Summary here";
            }
            base.DataBind();
        }

        public string Text { get; set; }

        protected override object SaveViewState()
        {
            ViewState["Text"] = Text;
            return base.SaveViewState();
        }

        protected override void LoadViewState(object savedState)
        {
            base.LoadViewState(savedState);
            Text = ViewState["Text"] as string;
        }

        protected override void Render(HtmlTextWriter writer)
        {
            if (!string.IsNullOrEmpty("Text"))
            {
                writer.RenderBeginTag(HtmlTextWriterTag.P);
                writer.Write(Text);
                writer.RenderEndTag();
            }
        }

    }
}
